import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mypeiwan/utils/peiwaninfobean.dart';
import 'package:mypeiwan/widgets/peiwaninfo2.dart';

class ReservationPeiwan extends StatefulWidget {
  int peiwanId;

  ReservationPeiwan(this.peiwanId);

  @override
  State<StatefulWidget> createState() {
    return _ReservationPeiwanState();
  }
}

class _ReservationPeiwanState extends State<ReservationPeiwan> {
  late PeiWanInfoBean peiWanInfoBean;

  @override
  void initState() {
    super.initState();
    peiWanInfoBean = new PeiWanInfoBean(
        2,
        "施莉",
        23,
        166,
        30,
        ["逛街看电影", "运动"],
        "本人性格开朗",
        0.3,
        0,
        45,
        [],
        "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1521521080,4202933966&fm=253&gp=0.jpg");
  }

  final List<String> items = [
    '逛街看电影',
    '美食探店',
    '密室剧本杀',
    '体育运动',
    '电竞网咖',
    '静吧酒馆',
    '量贩K歌',
    '一日游',
    '吃喝玩乐',
    '商务招待',
    '超高颜值'
  ];
  String? selectedValue;
  double hourPrice = 30;

  void showDateSelect() async {
    //获取当前的时间
    DateTime start = DateTime(2021, 1);
    //在当前的时间上多添加4天
    DateTime end = DateTime(start.year, start.month, start.day + 4);

    //显示时间选择器
    DateTimeRange? selectTimeRange = await showDateRangePicker(
        //语言环境
        locale: Locale("zh", "CH"),
        context: context,
        //开始时间
        firstDate: DateTime(2020, 1),
        //结束时间
        lastDate: DateTime(2022, 2),
        cancelText: "取消",
        confirmText: "确定",
        //初始的时间范围选择
        initialDateRange: DateTimeRange(start: start, end: end));
    //结果
    var _dateSelectText = selectTimeRange.toString();
    //选择结果中的开始时间
    DateTime? selectStart = selectTimeRange?.start;
    //选择结果中的结束时间
    DateTime? selectEnd = selectTimeRange?.end;

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: ListView(
          children: [
            Card(
              child: PeiwanInfo2(
                  peiWanInfoBean.name,
                  peiWanInfoBean.age,
                  peiWanInfoBean.height,
                  0.5,
                  true,
                  NetworkImage(peiWanInfoBean.headPicUrl)),
            ),
            Card(
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text("陪玩类型"),
                      DropdownButtonHideUnderline(
                          child: DropdownButton2(
                        isExpanded: true,
                        hint: Text(
                          '选择陪玩类型',
                          style: TextStyle(
                            fontSize: 14,
                            color: Theme.of(context).hintColor,
                          ),
                        ),
                        items: items
                            .map((String item) => DropdownMenuItem<String>(
                                  value: item,
                                  child: Text(
                                    item,
                                    style: const TextStyle(
                                      fontSize: 14,
                                    ),
                                  ),
                                ))
                            .toList(),
                        value: selectedValue,
                        onChanged: (String? value) {
                          setState(() {
                            selectedValue = value;
                          });
                        },
                        buttonStyleData: const ButtonStyleData(
                          padding: EdgeInsets.symmetric(horizontal: 16),
                          height: 40,
                          width: 140,
                        ),
                        menuItemStyleData: const MenuItemStyleData(
                          height: 40,
                        ),
                      )),
                    ],
                  ),
                  Divider(
                    height: 2.0,
                    indent: 0.0,
                    color: Colors.blueAccent,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [Text("单价"), Text("${hourPrice}元/小时")],
                  ),
                  Divider(
                    height: 2.0,
                    indent: 0.0,
                    color: Colors.blueAccent,
                  ),
                  Row(
                    children: [
                      Text("开始时间"),
                      SizedBox(
                        width: 130,
                      ),
                      Text("2023-06-15 21:00"),
                      IconButton(
                          onPressed: () {
                            showDateSelect();
                          }, icon: Icon(Icons.arrow_right))
                    ],
                  ),
                  Divider(
                    height: 2.0,
                    indent: 0.0,
                    color: Colors.blueAccent,
                  ),
                  Row(
                    children: [
                      Text("结束时间"),
                      SizedBox(
                        width: 150,
                      ),
                      Text("2023-06-15 21:00"),
                      Icon(Icons.arrow_right)
                    ],
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
